<template>
  <div>
    <!-- 头部   -->
    <Header></Header>

    <!-- 列表   -->
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs" :key="blog.id">
          <el-card>
            <h4>
              <!--路由跳转详情-->
              <router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
                {{ blog.title }}
              </router-link>
            </h4>
            <p>{{ blog.description }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </div>

    <!-- 分页-->
    <el-pagination class="mpage"
                   background
                   layout="prev, pager, next"
                   :total="total"
                   :page-size="pageSize"
                   :current-page="currentPage"
                   @current-change=list
    >
    </el-pagination>
  </div>
</template>

<script>
import Header from "@/components/Header"

export default {
  name: "Blogs",
  components: {
    Header
  },
  data() {
    return {
      blogs: {},
      currentPage: 1,
      total: 5,
      pageSize: 5
    }
  },
  methods: {
    list(currentPage) {
      this.$axios.get('/blog/blogs', {
        headers: {'authorization': this.$store.getters.getToken},
        params: {currentPage: currentPage}
      }).then(result => {
        this.blogs = result.data.data.records
        this.total = result.data.data.total
        this.pageSize = result.data.data.size
        this.currentPage = result.data.data.current
      })
    }
  },
  created() {
    this.list(1)
  }
}
</script>

<style scoped>
.mpage {
  margin: 30px;
  text-align: center;
}

.block{
  width: 50%;
  margin-left: auto;
  margin-right: auto;
}
</style>
